package top.hzy520.common.util;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import top.hzy520.common.constants.Parameter;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 21:15 2018/5/30
 */
@Component
public class ZkClient {
    @Autowired
    private Parameter parameter;

    @Bean
    public CuratorFramework getZkFrameWork(){
        CuratorFrameworkFactory.Builder builder=CuratorFrameworkFactory.builder()
                .connectionTimeoutMs(3000)
                .connectString(parameter.getZkHost())
                .retryPolicy(new RetryNTimes(5,500));
          CuratorFramework framework=builder.build();
          framework.start();
          return framework;
    }
}
